package com.keyroy.game.puzzle_rpg.dialogs;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.wb.swt.SWTResourceManager;

import com.keyroy.game.puzzle_rpg.models.environment.Battle;
import com.keyroy.game.puzzle_rpg.utils.UIUtil;
import com.keyroy.game.puzzle_rpg.views.BattleView;
import com.keyroy.game.puzzle_rpg.views.layouts.CenterLayout;

public class BattleDemoDialog extends Shell {
	private BattleView battleView;
	private Composite container;

	/**
	 * Launch the application.
	 * 
	 * @param args
	 */
	public static void main(String args[]) {
		try {
			Display display = Display.getDefault();
			BattleDemoDialog shell = new BattleDemoDialog(display, null);
			shell.open();
			shell.layout();
			while (!shell.isDisposed()) {
				if (!display.readAndDispatch()) {
					display.sleep();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the shell.
	 * 
	 * @param display
	 */
	public BattleDemoDialog(Display display, Battle battle) {
		super(display, SWT.SHELL_TRIM);
		setLayout(new FillLayout(SWT.HORIZONTAL));

		Menu menu = new Menu(this, SWT.BAR);
		setMenuBar(menu);

		MenuItem mntmNewSubmenu = new MenuItem(menu, SWT.CASCADE);
		mntmNewSubmenu.setText("\u73AF\u5883");

		Menu menu_1 = new Menu(mntmNewSubmenu);
		mntmNewSubmenu.setMenu(menu_1);

		MenuItem mntmNewItem = new MenuItem(menu_1, SWT.NONE);
		mntmNewItem.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				setSize(854, 480);
			}
		});
		mntmNewItem.setImage(SWTResourceManager.getImage(BattleDemoDialog.class, "/res/defaultview_misc.gif"));
		mntmNewItem.setText("\u5C4F\u5E55\u5927\u5C0F - 854x400");

		MenuItem mntmNewSubmenu_1 = new MenuItem(menu, SWT.CASCADE);
		mntmNewSubmenu_1.setText("\u5DE5\u5177");

		Menu menu_2 = new Menu(mntmNewSubmenu_1);
		mntmNewSubmenu_1.setMenu(menu_2);

		MenuItem mntmNewItem_1 = new MenuItem(menu_2, SWT.NONE);
		mntmNewItem_1.setAccelerator(SWT.F5);
		mntmNewItem_1.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(battleView != null){
					battleView.tips();
				}
			}
		});
		mntmNewItem_1.setImage(SWTResourceManager.getImage(BattleDemoDialog.class, "/res/quickassist_obj.gif"));
		mntmNewItem_1.setText("\u63D0\u793A");
		
		MenuItem menuItem = new MenuItem(menu, SWT.CASCADE);
		menuItem.setText("\u89C4\u5219");
		
		Menu menu_3 = new Menu(menuItem);
		menuItem.setMenu(menu_3);
		
		MenuItem mntmAlliesTurn = new MenuItem(menu_3, SWT.NONE);
		mntmAlliesTurn.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
			}
		});
		mntmAlliesTurn.setImage(SWTResourceManager.getImage(BattleDemoDialog.class, "/res/genericreggroup_obj.gif"));
		mntmAlliesTurn.setText("allies turn");
		
		MenuItem mntmEnemiesTurn = new MenuItem(menu_3, SWT.NONE);
		mntmEnemiesTurn.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
			}
		});
		mntmEnemiesTurn.setText("enemies turn");
		mntmEnemiesTurn.setImage(SWTResourceManager.getImage(BattleDemoDialog.class, "/res/genericreggroup_obj.gif"));
		
		new MenuItem(menu_3, SWT.SEPARATOR);
		
		MenuItem mntmNewItem_2 = new MenuItem(menu_3, SWT.NONE);
		mntmNewItem_2.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
			}
		});
		mntmNewItem_2.setImage(SWTResourceManager.getImage(BattleDemoDialog.class, "/res/synced(1).gif"));
		mntmNewItem_2.setText("\u6807\u51C6");

		container = new Composite(this, SWT.NONE);
		container.setLayout(new CenterLayout());
		createContents();

		setBattle(battle);
	}

	/**
	 * Create contents of the shell.
	 */
	protected void createContents() {
		setText("Puzzle Demo");
		setSize(1024, 600);

	}

	public void setBattle(Battle battle) {
		if (battle != null) {
			UIUtil.removeAll(container);
			battleView = new BattleView(container, battle);
			container.layout();
			battleView.setBackground(SWTResourceManager.getColor(0xee, 0xee, 0xee));
		}
	}

	@Override
	protected void checkSubclass() {
	}
}
